<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Puppet安装和配置 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Puppet安装和配置</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Puppet/">Puppet</a>
			</span>
		
	</div>

	

	
		<h2 id="一、准备工作"><a href="#一、准备工作" class="headerlink" title="一、准备工作"></a>一、准备工作</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;两台机器：192.168.0.93（服务端）  192.168.0.92 （客户端）</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;两台机器关闭selinux，清空iptables规则，并保存，设置hostname</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.93 上 hostname web9.yanyi.com </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 /etc/sysconfig/network  定义hostname</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/sysconfig/network</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/01.png?raw=true" alt="01"><figcaption class="figure__caption">01</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.92 上 hostname web10.yanyi.com</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 /etc/sysconfig/network  定义hostname</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># vim /etc/sysconfig/network</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/02.png?raw=true" alt="02"><figcaption class="figure__caption">02</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑hosts文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/hosts</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># vim /etc/hosts</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.93 和 192.168.0.92全部为</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/03.png?raw=true" alt="03"><figcaption class="figure__caption">03</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;两台机器安装ntpdate，并建立自动同步时间的任务计划：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># yum install -y ntp</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># yum install -y ntp</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;crontab -e #加入</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># crontab -e</span></div><div class="line">*/10 * * * * ntpdate time.windows.com &gt;/dev/null 2&gt;&amp;1</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># crontab -e</span></div><div class="line">*/10 * * * * ntpdate time.windows.com &gt;/dev/null 2&gt;&amp;1</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/04.png?raw=true" alt="04"><figcaption class="figure__caption">04</figcaption></figure></p>
<h2 id="二、安装-puppet"><a href="#二、安装-puppet" class="headerlink" title="二、安装 puppet"></a>二、安装 puppet</h2><h3 id="1-安装服务端"><a href="#1-安装服务端" class="headerlink" title="1.安装服务端"></a>1.安装服务端</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端（192.138.0.93）上</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装puppet 源</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># rpm -ivh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装服务端程序</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># yum install -y puppet-server</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># service puppetmaster start</span></div><div class="line">启动 puppetmaster： [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;开机启动</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># chkconfig puppetmaster on</span></div></pre></td></tr></table></figure>
<h3 id="2-安装客户端"><a href="#2-安装客户端" class="headerlink" title="2.安装客户端"></a>2.安装客户端</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;客户端（192.168.0.92）上</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装puppet 源</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># rpm -ivh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装客户端程序</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># yum install -y puppet</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改配置文件  /etc/puppet/puppet.conf 在最后面添加</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">server = web9.yanyi.com</div><div class="line"> runinterval = 10</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># vim /etc/puppet/puppet.conf</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/05.png?raw=true" alt="05"><figcaption class="figure__caption">05</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># service puppet start</span></div><div class="line">Starting puppet agent:         [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;开机启动</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># chkconfig puppet on</span></div></pre></td></tr></table></figure>
<h2 id="三、配置认证"><a href="#三、配置认证" class="headerlink" title="三、配置认证"></a>三、配置认证</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端查看客户端证书列表 puppet cert list –all #如果签发的证书，会本行最前面带一个+</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert list --all</span></div><div class="line"> <span class="string">"web10.yanyi.com"</span> (SHA256) 16:BF:29:D2:D3:56:18:25:CE:8E:E3:89:E7:6E:08:65:BB:BC:F7:1F:98:86:0D:DA:C8:48:B8:60:75:A8:77:94</div><div class="line">+ <span class="string">"web9.yanyi.com"</span> (SHA256) F6:E5:87:3B:AF:F1:A0:37:D9:5E:05:B1:19:FB:49:C7:AE:EC:DD:B6:4F:F5:11:BE:70:18:3D:46:A8:FE:E5:A0 (alt names: <span class="string">"DNS:puppet"</span>, <span class="string">"DNS:puppet.yanyi.com"</span>, <span class="string">"DNS:web9.yanyi.com"</span>)</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;客户端上生成ssl证书 puppet agent –test  –server web9.yanyi.com</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet agent --test --server web9.yanyi.com</span></div><div class="line">Warning: Unable to fetch my node definition, but the agent run will <span class="built_in">continue</span>:</div><div class="line">Warning: undefined method `include?<span class="string">' for nil:NilClass</span></div><div class="line"><span class="string">Info: Retrieving pluginfacts</span></div><div class="line"><span class="string">Info: Retrieving plugin</span></div><div class="line"><span class="string">Info: Caching catalog for web9.yanyi.com</span></div><div class="line"><span class="string">Info: Applying configuration version '</span>1487260353<span class="string">'</span></div><div class="line"><span class="string">Info: Creating state file /var/lib/puppet/state/state.yaml</span></div><div class="line"><span class="string">Notice: Finished catalog run in 0.01 seconds</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端签发指定客户端证书</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert --sign web10.yanyi.com</span></div><div class="line">Notice: Signed certificate request <span class="keyword">for</span> web10.yanyi.com</div><div class="line">Notice: Removing file Puppet::SSL::CertificateRequest web10.yanyi.com at <span class="string">'/var/lib/puppet/ssl/ca/requests/web10.yanyi.com.pem'</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;执行 puppet cert list –all 看是否成功</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert list --all </span></div><div class="line">+ <span class="string">"web10.yanyi.com"</span> (SHA256) 50:B7:39:53:62:3C:BA:AF:BD:7B:B3:48:99:B7:3D:B2:9D:DE:5E:34:71:FD:3A:2B:8A:34:98:09:2C:02:6F:87</div><div class="line">+ <span class="string">"web9.yanyi.com"</span> (SHA256) F6:E5:87:3B:AF:F1:A0:37:D9:5E:05:B1:19:FB:49:C7:AE:EC:DD:B6:4F:F5:11:BE:70:18:3D:46:A8:FE:E5:A0 (alt names: <span class="string">"DNS:puppet"</span>, <span class="string">"DNS:puppet.yanyi.com"</span>, <span class="string">"DNS:web9.yanyi.com"</span>)</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端可以删除指定客户端证书</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert clean web10.yanyi.com</span></div><div class="line">Notice: Revoked certificate with serial 3</div><div class="line">Notice: Removing file Puppet::SSL::Certificate web10.yanyi.com at <span class="string">'/var/lib/puppet/ssl/ca/signed/web10.yanyi.com.pem'</span></div><div class="line">Notice: Removing file Puppet::SSL::Certificate web10.yanyi.com at <span class="string">'/var/lib/puppet/ssl/certs/web10.yanyi.com.pem'</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert list --all </span></div><div class="line">+ <span class="string">"web9.yanyi.com"</span> (SHA256) F6:E5:87:3B:AF:F1:A0:37:D9:5E:05:B1:19:FB:49:C7:AE:EC:DD:B6:4F:F5:11:BE:70:18:3D:46:A8:FE:E5:A0 (alt names: <span class="string">"DNS:puppet"</span>, <span class="string">"DNS:puppet.yanyi.com"</span>, <span class="string">"DNS:web9.yanyi.com"</span>)</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;删除所有证书 puppet cert clean –all</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert clean --all</span></div><div class="line">Notice: Revoked certificate with serial 2</div><div class="line">Notice: Removing file Puppet::SSL::Certificate web9.yanyi.com at <span class="string">'/var/lib/puppet/ssl/ca/signed/web9.yanyi.com.pem'</span></div><div class="line">Notice: Removing file Puppet::SSL::Certificate web9.yanyi.com at <span class="string">'/var/lib/puppet/ssl/certs/web9.yanyi.com.pem'</span></div><div class="line">Notice: Removing file Puppet::SSL::Key web9.yanyi.com at <span class="string">'/var/lib/puppet/ssl/private_keys/web9.yanyi.com.pem'</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;删除所有证书以后，服务端执行 puppet agent –test  –server web9.yanyi.com</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet agent --test --server web9.yanyi.com </span></div><div class="line">Info: Creating a new SSL key <span class="keyword">for</span> web9.yanyi.com</div><div class="line">Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml</div><div class="line">Info: Creating a new SSL certificate request <span class="keyword">for</span> web9.yanyi.com</div><div class="line">Info: Certificate Request fingerprint (SHA256): AF:C5:3E:47:E7:6F:38:11:C5:F9:04:EB:05:8D:81:A1:FF:4E:8F:89:0B:28:38:A2:79:8F:B2:1A:D2:D5:26:A3</div><div class="line">Exiting; no certificate found and waitforcert is disabled</div><div class="line">[root@web9 ~]<span class="comment"># puppet cert list --all </span></div><div class="line"> <span class="string">"web9.yanyi.com"</span> (SHA256) AF:C5:3E:47:E7:6F:38:11:C5:F9:04:EB:05:8D:81:A1:FF:4E:8F:89:0B:28:38:A2:79:8F:B2:1A:D2:D5:26:A3</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;客户端需删除 ssl 目录下所有文件并重启服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># rm -rf /var/lib/puppet/ssl/*</span></div><div class="line">[root@web10 ~]<span class="comment"># service puppet restart</span></div><div class="line">Stopping puppet agent: [确定]</div><div class="line">Starting puppet agent: [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后服务端查看，并重签</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert list --all </span></div><div class="line"> <span class="string">"web10.yanyi.com"</span> (SHA256) 58:48:87:28:06:26:CA:53:86:31:A0:78:B7:55:E5:F7:6E:C2:3E:5E:19:48:19:C3:96:E9:42:9F:D9:96:13:EC</div><div class="line"> <span class="string">"web9.yanyi.com"</span> (SHA256) AF:C5:3E:47:E7:6F:38:11:C5:F9:04:EB:05:8D:81:A1:FF:4E:8F:89:0B:28:38:A2:79:8F:B2:1A:D2:D5:26:A3</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert --sign web9.yanyi.com</span></div><div class="line">Notice: Signed certificate request <span class="keyword">for</span> web9.yanyi.com</div><div class="line">Notice: Removing file Puppet::SSL::CertificateRequest web9.yanyi.com at <span class="string">'/var/lib/puppet/ssl/ca/requests/web9.yanyi.com.pem'</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert --sign web10.yanyi.com</span></div><div class="line">Notice: Signed certificate request <span class="keyword">for</span> web10.yanyi.com</div><div class="line">Notice: Removing file Puppet::SSL::CertificateRequest web10.yanyi.com at <span class="string">'/var/lib/puppet/ssl/ca/requests/web10.yanyi.com.pem'</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert list --all </span></div><div class="line">+ <span class="string">"web10.yanyi.com"</span> (SHA256) B0:2C:B1:C4:B7:E3:3E:1A:40:99:D2:4F:6F:E3:1E:1E:24:69:22:07:68:D9:C9:F4:9E:5F:4A:D9:BF:35:F6:27</div><div class="line">+ <span class="string">"web9.yanyi.com"</span> (SHA256) D0:49:21:D3:4E:B6:EA:48:19:4D:29:F4:4C:A1:16:77:BC:DD:8E:BA:73:6C:83:0A:37:5F:5D:F8:0B:67:B1:B7</div></pre></td></tr></table></figure>
<h2 id="四、-配置自动签发证书"><a href="#四、-配置自动签发证书" class="headerlink" title="四、 配置自动签发证书"></a>四、 配置自动签发证书</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端删除客户端证书 puppet cert clean web10.yanyi.com</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert clean web10.yanyi.com</span></div><div class="line">Notice: Revoked certificate with serial 5</div><div class="line">Notice: Removing file Puppet::SSL::Certificate web10.yanyi.com at <span class="string">'/var/lib/puppet/ssl/ca/signed/web10.yanyi.com.pem'</span></div><div class="line">Notice: Removing file Puppet::SSL::Certificate web10.yanyi.com at <span class="string">'/var/lib/puppet/ssl/certs/web10.yanyi.com.pem'</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;客户端删除ssl相关文件 rm -rf /var/lib/puppet/ssl/*</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># rm -rf /var/lib/puppet/ssl/*</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端创建自动签发的配置文件 /etc/puppet/autosign.conf</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/puppet/authsign.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入如下内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">*.yanyi.com</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改服务端 puppet 配置文件 /etc/puppet/puppet.conf</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/puppet/puppet.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 [main] 下加入内容 autosign = true</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/06.png?raw=true" alt="06"><figcaption class="figure__caption">06</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端重启puppetmaster服务  /etc/init.d/puppetmaster restart</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># service puppetmaster restart</span></div><div class="line">停止 puppetmaster： [确定]</div><div class="line">启动 puppetmaster： [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;客户端重启puppet服务 /etc/init.d/puppet restart</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># service puppet restart</span></div><div class="line">Stopping puppet agent: [确定]</div><div class="line">Starting puppet agent: [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端 puppet cert list –all#可以看到web10.aming.com已经签名</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果客户端不重启puppet服务，也可以通过命令来自动签发</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;puppet agent –test –server web9.yanyi.com</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert clean --all </span></div><div class="line">Notice: Revoked certificate with serial 6</div><div class="line">Notice: Removing file Puppet::SSL::Certificate web9.yanyi.com at <span class="string">'/var/lib/puppet/ssl/ca/signed/web9.yanyi.com.pem'</span></div><div class="line">Notice: Removing file Puppet::SSL::Certificate web9.yanyi.com at <span class="string">'/var/lib/puppet/ssl/certs/web9.yanyi.com.pem'</span></div><div class="line">Notice: Removing file Puppet::SSL::Key web9.yanyi.com at <span class="string">'/var/lib/puppet/ssl/private_keys/web9.yanyi.com.pem'</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet agent --test --server web9.yanyi.com</span></div><div class="line">Info: Creating a new SSL key <span class="keyword">for</span> web9.yanyi.com</div><div class="line">Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml</div><div class="line">Info: Creating a new SSL certificate request <span class="keyword">for</span> web9.yanyi.com</div><div class="line">Info: Certificate Request fingerprint (SHA256): 84:AA:7D:13:C6:9C:F6:8E:25:7E:27:69:7C:1E:12:F1:8C:D9:D6:3B:49:74:83:E3:1A:15:9F:F0:37:F7:35:84</div><div class="line">Exiting; no certificate found and waitforcert is disabled</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet cert list --all </span></div><div class="line">+ <span class="string">"web10.yanyi.com"</span> (SHA256) 92:F3:04:9E:01:D5:A6:4B:BF:51:22:89:A2:51:F9:7A:1E:D1:53:13:19:49:2A:3D:58:9D:38:39:17:D3:AC:E2</div><div class="line">+ <span class="string">"web9.yanyi.com"</span> (SHA256) 26:5D:91:D4:B9:58:62:66:CB:48:6A:3F:CB:51:5B:DD:4C:9B:72:39:34:6E:01:C5:41:C6:DB:EE:93:3F:5D:20 (alt names: <span class="string">"DNS:puppet"</span>, <span class="string">"DNS:puppet.yanyi.com"</span>, <span class="string">"DNS:web9.yanyi.com"</span>)</div></pre></td></tr></table></figure>
<h2 id="五、测试证书"><a href="#五、测试证书" class="headerlink" title="五、测试证书"></a>五、测试证书</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端编辑配置文件 /etc/puppet/manifests/site.pp </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/puppet/manifests/site.pp</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加如下内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">node default &#123;</div><div class="line">file &#123;<span class="string">"/tmp/123.txt"</span>:</div><div class="line">content =&gt; <span class="string">"test,test"</span>;</div><div class="line">     &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/07.png?raw=true" alt="07"><figcaption class="figure__caption">07</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：如果不配置该文件，则客户端不会同步任何数据</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;客户端上稍等一会（每隔30s会自动执行服务端上的任务），或者直接命令行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># puppet agent --test --server web9.yanyi.com</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样在客户端的/tmp/下会有个123.txt文件，内容为test,test</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># ls /tmp</span></div><div class="line">123.txt yum.log</div><div class="line">[root@web10 ~]<span class="comment"># cat /tmp/123.txt</span></div><div class="line"><span class="built_in">test</span>,<span class="built_in">test</span></div></pre></td></tr></table></figure>
<h2 id="六、配置模块"><a href="#六、配置模块" class="headerlink" title="六、配置模块"></a>六、配置模块</h2><h3 id="定义模块管理"><a href="#定义模块管理" class="headerlink" title="定义模块管理"></a>定义模块管理</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;模块是 puppet 的配置单元，模块里面会包含类和资源。同步文件、远程执行命令、cron 等叫做资源，都是通过模块来实现的。下面我们来写一个模块</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端创建目录 mkdir /etc/puppet/modules/testm这个目录名字也作为模块名字</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># mkdir /etc/puppet/modules/testm</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后继续创建模块对应的子目录 </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># mkdir /etc/puppet/modules/testm/&#123;files,manifests,templates&#125;</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;files里面存文件，可以留空，manifests里面是配置文件，templates里面是模块文件可以为空</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 files 创建文件 1.txt，内容随意</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建配置文件 /etc/puppet/modules/testm/manifests/init.pp</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/puppet/modules/testm/manifests/init.pp</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内容为</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">class testm&#123;</div><div class="line">file &#123;<span class="string">"/tmp/2.txt"</span>:</div><div class="line">      owner =&gt; <span class="string">"root"</span>,</div><div class="line">      group =&gt; <span class="string">"root"</span>,</div><div class="line">      mode =&gt; 0400,</div><div class="line">      <span class="built_in">source</span> =&gt; <span class="string">"puppet://<span class="variable">$puppetserver</span>/modules/testm/1.txt"</span></div><div class="line">&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/08.png?raw=true" alt="08"><figcaption class="figure__caption">08</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：类名字也叫做testm, 类下面定义了一个资源file，文件名字叫做/tmp/2.txt ，  owner，group，mode定义文件的属主、数组以及权限，source定义这个文件从哪里获取。 $puppetserver一会也要定义一下，这里指的是puppet server服务器上/etc/puppet/modules/testm/files/1.txt</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下面要继续定义一个很关键的配置文件：/etc/puppet/manifests/site.pp </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/puppet/manifests/site.pp</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内容如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="variable">$puppetserver</span> = <span class="string">'web9.yanyi.com'</span></div><div class="line">node <span class="string">'web10.yanyi.com'</span>&#123;</div><div class="line">include testm</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/09.png?raw=true" alt="09"><figcaption class="figure__caption">09</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：$puppetserver 定义服务端的主机名，node后面为客户端的主机名，这里面定义该客户端要加载的模块</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置完成后，在客户端执行命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># puppet agent --test --server=web9.aming.com</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果客户端上启动了puppet服务，不用执行这命令，它也会自动同步的</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/10.png?raw=true" alt="10"><figcaption class="figure__caption">10</figcaption></figure></p>
<h2 id="七、文件或目录资源"><a href="#七、文件或目录资源" class="headerlink" title="七、文件或目录资源"></a>七、文件或目录资源</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;上面的模块其实只是同步了一个文件而已，那么要想同步一个目录如何做？我们可以通过实现同步一个目录来做一个包发布系统。 比如在一台机器上编译安装好了apache，那么就可以通过这样的模块把这个apache目录整个分发到其他机器上。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># cd /etc/puppet//modules/</span></div><div class="line">[root@web9 modules]<span class="comment"># ls</span></div><div class="line">testm</div><div class="line">[root@web9 modules]<span class="comment"># cd testm</span></div><div class="line">[root@web9 testm]<span class="comment"># ls</span></div><div class="line">files manifests templates</div><div class="line">[root@web9 testm]<span class="comment"># cd manifests/</span></div><div class="line">[root@web9 manifests]<span class="comment"># ls</span></div><div class="line">init.pp</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;模块配置文件如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 manifests]<span class="comment"># vim init.pp</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">class apache&#123;</div><div class="line">file &#123;<span class="string">"/usr/local/apache2"</span>:</div><div class="line">owner =&gt; <span class="string">"root"</span>,</div><div class="line">group =&gt; <span class="string">"root"</span>,</div><div class="line"><span class="built_in">source</span> =&gt; <span class="string">"puppet://<span class="variable">$puppetserver</span>/modules/apache/apache2"</span>,</div><div class="line">recurse =&gt; <span class="literal">true</span>,</div><div class="line">purge =&gt; <span class="literal">true</span></div><div class="line">&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/11.png?raw=true" alt="11"><figcaption class="figure__caption">11</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;其中recurse=&gt;true 这个参数很关键，它表示递归的意思，没有这个不能同步目录。 purge参数可以保证当服务端删除某个文件，客户端可以跟着删除。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;因实验虚拟机没 apache 目录更改为  testm </p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/12.png?raw=true" alt="12"><figcaption class="figure__caption">12</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;参考<a href="https://hcldirgit.github.io/2017/08/20/Puppet/2.%20Puppet%E5%AD%A6%E4%B9%A0%E4%B9%8B%E6%96%87%E4%BB%B6%E7%AE%A1%E7%90%86/" target="_blank" rel="external">Puppet学习之文件管理</a></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 puppet 目录下有个  manifests 目录，编辑下边的配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 puppet]<span class="comment"># cd manifests/</span></div><div class="line">[root@web9 manifests]<span class="comment"># ls</span></div><div class="line">site.pp</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 manifests]<span class="comment"># vim site.pp</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容 include apache</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">include apache</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/13.png?raw=true" alt="13"><figcaption class="figure__caption">13</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看 客户端 /usr/local 目录，下边多了 apache2 文件夹</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/14.png?raw=true" alt="14"><figcaption class="figure__caption">14</figcaption></figure></p>
<h2 id="八、远程执行命令"><a href="#八、远程执行命令" class="headerlink" title="八、远程执行命令"></a>八、远程执行命令</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件 /etc/puppet/modules/testm/manifests/init.pp</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/puppet/modules/testm/manifests/init.pp</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">exec &#123;&quot;123&quot;:</div><div class="line">   unless =&gt; &quot;test -f /tmp/yanyi.txt&quot;,</div><div class="line">   path =&gt; [&quot;/bin&quot;, &quot;/sbin&quot;, &quot;/usr/bin&quot;, &quot;/usr/sbin&quot;],</div><div class="line">   command =&gt; &quot;touch /tmp/yanyi.txt&quot;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/15.png?raw=true" alt="15"><figcaption class="figure__caption">15</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：123只是作为该资源的一个名字，unless后面的命令作为一个条件，当条件成立时，不会执行下面的命令，如果想要条件成立时，执行下面的命令，用 onlyif。要注意的是，我们一定要给执行的这条命令加个条件，使用unless就可以，必须满足这个条件才能执行命令，否则这个命令会一直执行，不太妥当。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看客户端的 tmp 是否生成 yanyi.txt 文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># ls -lt /tmp</span></div><div class="line">总用量 8</div><div class="line">-rw-r--r-- 1 root root 0 2月 20 23:31 yanyi.txt</div><div class="line">-r-------- 1 root root 6 2月 17 04:30 2.txt</div><div class="line">-rw-r--r-- 1 root root 9 2月 17 03:40 123.txt</div><div class="line">-rw-------. 1 root root 0 2月 15 06:16 yum.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;参考 <a href="https://hcldirgit.github.io/2017/08/20/Puppet/4.%20Puppet%20exec/" target="_blank" rel="external">puppet exec</a></p>
<h2 id="九、任务计划"><a href="#九、任务计划" class="headerlink" title="九、任务计划"></a>九、任务计划</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件 /etc/puppet/modules/testm/manifests/init.pp</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/puppet/modules/testm/manifests/init.pp</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">cron &#123;<span class="string">"yanyi1"</span>:</div><div class="line">    <span class="built_in">command</span> =&gt; <span class="string">"/sbin/ntpdate time.windows.com"</span>,</div><div class="line">    user =&gt; <span class="string">"root"</span>,</div><div class="line">    minute =&gt; <span class="string">"*/10"</span>,</div><div class="line">    <span class="comment">#ensure =&gt; "absent"</span></div><div class="line">    &#125;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/16.png?raw=true" alt="16"><figcaption class="figure__caption">16</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：分时日月周分别对应puppet里面的minute，hour，monthday，month，weekday,ensure设置为absent为删除该任务，如果不设置改行则为建立</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看客户端是否生成该计划任务</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Puppet%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AE/17.png?raw=true" alt="17"><figcaption class="figure__caption">17</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;参考 <a href="https://hcldirgit.github.io/2017/08/20/Puppet/3.%20Puppet%20cron/" target="_blank" rel="external">puppet cron</a></p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Puppet/1. Puppet安装和配置/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
